<?php

namespace admin;

class loginCon
{
    //登录页面
    function index(){
        show();
    }
    function submit(){
        $login_cachekey='login_'.M_ip();
        $try_time=20;//15分钟内允许尝试的次数
        $login_error_time=Cache("ucmslogin/".$login_cachekey);
        $username=I("uuu_username");
        if(!$login_error_time) {$login_error_time=0;}
        if(!$username){
            jsonMsg(["code"=>0,"msg"=>"请输入完整参数"]);
        }
        if($login_error_time<=$try_time) {
            global $power;
            $username=trim($username);
            $password=Fun::passwordMd5(trim($_POST['uuu_password']));
            $link=Mod::getUser(["username"=>$username,"psd"=>$password]);
            if($link && $password==$link['psd']) {
                $power=json_decode($link['power'],1);
                if(!power('b',1,$power)) {
                    jsonMsg(["code"=>1,"msg"=>"该账户已禁用"]);
                }else {
                    Fun::setAdminName($link['username']);
                    Fun::setAdminPsd($link['psd']);
                    cache('ucmslogin/'.$login_cachekey,null);
                    jsonMsg(["code"=>0,"msg"=>"登录成功"]);
                }
            }else {
                cache('ucmslogin/'.$login_cachekey,$login_error_time+1,900);
                jsonMsg(["code"=>1,"msg"=>"您填写的账户信息有误"]);
            }
        }else {
            cache('ucmslogin/'.$login_cachekey,$login_error_time+1,900);
            jsonMsg(["code"=>1,"msg"=>"登录过于频繁,请稍后再试"]);
        }
    }
}